package org.webball.pitch;

import org.webball.base.abstracts.AbstractPlayer;
import org.webball.base.interfaces.ITeam;

/**
 * 
 * @author Maciej Koch
 *
 */
public class Team implements ITeam{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2836492614899730446L;
	
	public static final int T1 = 0;
	public static final int T2 = 1;
	private AbstractPlayer[] players;
	private int points = 0;
	private int setPoints = 0;
	private boolean newSet = false;
	private int hittingPlayer = -1;
	
	public Team(AbstractPlayer[] players)
	{
		this.players = players;
	}
	@Override
	public int getPoints() {
		return points;
	}

	@Override
	public int getSetpoints() {
		return setPoints;
	}

	@Override
	public AbstractPlayer getPlayer(int i) {
		if(i >=0 && i < 6)
			return players[i];
		return null;
	}
	@Override
	public void copy(ITeam team) {
		this.players = team.getAllPlayers();
		this.points = team.getPoints();
		this.setPoints = team.getSetpoints();
		
	}
	@Override
	public AbstractPlayer[] getAllPlayers() {
		return players;
	}
	public void changePosition() {
		AbstractPlayer[] tmp = new AbstractPlayer[6];
		for(int i = 0 ; i < players.length ; i++) {	
			if(i == players.length - 1)
				tmp[0] = players[i];
			else
				tmp[i+1] = players[i];
		}	
		players = tmp;
	}
	@Override
	public void addPoint() {
		newSet = false;
		points++;
		if(points == 25) {
			points = 0;
			setPoints++;
			newSet = true;
		}
		
	}
	@Override
	public boolean isNewSet() {
		// TODO Auto-generated method stub
		return newSet;
	}
	
	public int getHittingPlayer() {
		return hittingPlayer;
	}
	public void setHittingPlayer(int hittingPlayer) {
		this.hittingPlayer = hittingPlayer;
	}
}
